'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-11-21 11:09:06
'''
#
# @lc app=leetcode.cn id=560 lang=python3
#
# [560] 和为K的子数组
#

# @lc code=start
from typing import List
class Solution:
    def subarraySum(self, nums: List[int], k: int) -> int:
        import collections
        store = collections.defaultdict(lambda:0)
        store[0]+=1
        pref=0
        ans=0
        for n in nums:
            pref+=n
            ans+=store[pref-k]
            store[pref]+=1
        return ans
# @lc code=end

